/*
** Copyright (c) 2014-2017 The XCast project. All rights reserved.
*/
#ifndef XCAST_H_
#define XCAST_H_

#include "./include/xcast_const.h"
#include "./include/xcast_variant.h"
#include "./include/xcast_error.h"

#ifdef __cplusplus
extern "C" {
#endif

/* xcast audio frame detail format declaration */
typedef struct xcast_audio_format_s {
  xc_media_format               id;               /* format id declared in 'xc_media_format' */

  uint32_t                      channel_count;
  uint32_t                      sample_rate;
  uint32_t                      bits_per_sample;  /* number of bits per sample */
} xcast_audio_format_t;

/* xcast video frame detail format declaration */
typedef struct xcast_video_format_s {
  xc_media_format               id;               /* format id declared in 'xc_media_format' */

  uint32_t                      width;            /* video width */
  uint32_t                      height;           /* video height */
  xc_rotation                   rotate;           /* video rotation of type 'xc_rotation' */
  int32_t                       media_source;     /* source type of 'xc_media_source' */
  uint64_t                      timestamp;        /* video timestamp */
} xcast_video_format_t;

/* xcast texture type which can use hardware acceleration */
typedef struct xcast_texture_s {
  xc_texture_type               type;

  union {
    uint32_t                    id;               /* texture id for opengl */
    void                       *handle;           /* for directx, etc */
  };
} xcast_texture_t;

/* xcast media frame structure for audio/video/texture frame data */
typedef struct xcast_media_frame_s {
  const char                   *source;           /* from where the frame comes */
  const char                   *parent;           /* parent of the 'source' if any */

  uint64_t                      uin;              /* frame uin */
  xc_media_frame_type           type;             /* frame type */

  union {
    xcast_audio_format_t const *audio;            /* audio frame format */
    xcast_video_format_t const *video;            /* video frame format */
  };

  union {
    struct {
      uint32_t                  size;             /* frame data content size */
      uint8_t const            *data;             /* binary data content */
    }                           buf;

    xcast_texture_t            *texture;          /* texture content */
  };

  unsigned                      is_texture : 1;
} xcast_media_frame_t;

/*
* query current xcast string version.
*/
xcast_export const char *xcast_version(void);

/*
* query current xcast error message.
*/
xcast_export const char *xcast_err_msg(void);

/*
* start xcast before xcast streaming.
*/
xcast_export int32_t xcast_startup(xcast_variant_t *settings);

/*
* shutdown xcast after streaming.
*/
xcast_export void xcast_shutdown(void);

/*
* get property with the given property path.
*/
xcast_export xcast_variant_t *xcast_get_property(const char *prop);

/*
* set property with the given property path.
*/
xcast_export int32_t xcast_set_property(const char *prop, xcast_variant_t *val);

/*
* execute with the given path.
*/
xcast_export int32_t xcast_execute(const char *path, xcast_variant_t *val);

/*
* register/unregister event callback into xcast to receive event notify.
* if the 'handler' is null, the callback is unregistered from xcast.
*/
xcast_export int32_t xcast_handle_event(
  const char *event_path, xcast_func_pt handler, void *user_data);

/* 
* start xcast channel for streaming with params. 
*/
xcast_export int32_t xcast_start_channel(const char *id, xcast_variant_t *params);

/* 
* close xcast channel and stop streaming. 
*/
xcast_export int32_t xcast_stop_channel(const char *id);

/* 
* only for passive mode, drive xcast cycle.
* if block set false, you should call xcast_cycle some where to drive xcast.
*/
xcast_export void xcast_cycle(bool block);

/* 
* only for passive mode, break xcast cycle while xcast_cycle block param set to true.
*/
xcast_export void xcast_cycle_break(bool cycle_break);
    
#ifdef __cplusplus
}
#endif

#endif /* XCAST_H_ */
